﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class Stat_IpStat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StatInit();
            BIND();
        }
    }

    private void StatInit()
    {
        StatChartlet.Visible = false;
        txtYears.Text = DateTime.Now.Year.ToString();
        txtMonths.Text = DateTime.Now.Month.ToString();
        txtDays.Text = DateTime.Now.Day.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BIND();
    }

    private void BIND()
    {
        StatChartlet.Visible = true;
        Usas.BLL.Cms.StatOperate so = new Usas.BLL.Cms.StatOperate();
        ArrayList XTitle = new ArrayList();

        ArrayList[] ChartData = new ArrayList[1];
        ChartData[0] = new ArrayList();

        string years = txtYears.Text.Trim().Length > 0 ? " and years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " and months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " and days=" + txtDays.Text.Trim() : "";

        for (int i = 0; i < 11; i++)
        {
            object obj = null;
            if (i > 9)
            {
                obj = so.IpStat(years, months, days, " and sumNum>=" + i);
            }
            else
            {
                obj = so.IpStat(years, months, days, " and sumNum=" + i);
            }

            if (obj == null || obj.ToString() == "")
            {
                obj = "0";
            }

            XTitle.Add(i > 9 ? "10次以上" : i.ToString() + "次");
            //object b = ds.Tables[0].Rows[0][i] == null || ds.Tables[0].Rows[0][i].ToString() == "0" || ds.Tables[0].Rows[0][i].ToString() == "" ? "0" : ds.Tables[0].Rows[0][i].ToString();
            ChartData[0].Add(obj.ToString());
        }

        StatChartlet.ChartTitle.Text = (txtYears.Text.Trim().Length > 0 ? txtYears.Text.Trim() + "年" : "")
          + (txtMonths.Text.Trim().Length > 0 ? txtMonths.Text.Trim() + "月" : "")
          + (txtDays.Text.Trim().Length > 0 ? txtDays.Text.Trim() + "日" : "")
          + "时段回访统计";
        StatChartlet.YLabels.UnitText = "人数";
        StatChartlet.XLabels.UnitText = "次数";

        StatChartlet.InitializeData(ChartData, XTitle, null);
    }
}
